import { request } from '@umijs/max';

/**
 * 登录
 * @param body
 * @param options
 */
export async function doLogin(body: LoginParams, options?: { [key: string]: any }) {
  return request<ResponseMessage<UserToken>>('/authorize/login', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/**
 * 退出登录
 * @param options
 */
export async function signOut(options?: { [key: string]: any },) {
  return request<ResponseMessage<any>>('/authorize/logout', {
    method: 'DELETE',
    ...(options || {}),
  });
}

/**
 * 获取登录验证码
 * @param params
 * @param options
 */
export async function queryLoginCaptcha(
  params?: {
    width?: string,
    height?: string;
  },
  options?: { [key: string]: any },
) {
  return request<ResponseMessage<CaptchaInfo>>('/captcha/image', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/**
 * 查询用户信息详情
 * @param options
 */
export async function queryCurrentUserDetail(options?: { [key: string]: any },) {
  return request<ResponseMessage<any>>('/authorize/me', {
    method: 'GET',
    ...(options || {}),
  });
}

/**
 * 发送邮箱验证码
 * @param params
 * @param options
 */
export async function sendCaptcha(
  params?: {
    to?: string
    },
  options?: { [key: string]: any },) {
  return request<ResponseMessage<any>>('/email/captcha', {
    method: 'GET',
    params: {
      ...params
    },
    ...(options || {}),
  });
}
